# coding: utf-8
from dataclasses import dataclass
from enum import Enum
from typing import Union

from PySide6.QtGui import QImage


class TaskStatus(Enum):
    WAIT = '等待中'
    DOING = '进行中'
    PAUSE = '暂停中'
    DONE = '已完成'
    ERROR = '错误'
    CANCEL = '取消'

    @staticmethod
    def str_to(status_str: str) -> 'TaskStatus':
        for status in TaskStatus:
            if status.value == status_str:
                return status
        return None


@dataclass
class TaskMessage:
    id: str = None  # 任务ID
    message: str = '无'  # 消息，日志
    progress: float = 0.0  # 进度百分比
    status: TaskStatus = TaskStatus.WAIT  # 任务状态
    net_speed: str = '0 MB/S'  # 网速
    downloaded_msg: str = '0MB / 0MB'  # 下载信息， 123MB / 400MB
    error_msg: str = '无'  # 错误信息
    cover: Union[QImage, str] = None
